package com.drama.api.sys.recycle.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.drama.api.base.*;
import com.drama.api.company.dramas.service.ICompanyDramasService;
import com.drama.api.sys.dramas.domain.vo.SysDramasSearchVO;
import com.drama.api.sys.dramas.domain.vo.SysDramasVO;
import com.drama.api.sys.dramas.service.ISysDramasService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.SysRecycleDramasController)
@RequestMapping(value = "/api/sys/recycle_dramas")
@RestController
@SaCheckLogin
public class SysRecycleDramasController {

    @Autowired
    private ISysDramasService service;
    @Autowired
    private ICompanyDramasService companyDramasService;

    @ApiOperation(value = "查询剧目列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<SysDramasVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute SysDramasSearchVO searchVO) {
        List<SysDramasVO> list = service.getRecycleList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }


    @ApiOperation(value = "删除剧目[彻底删除-清除资源]")
    @PostMapping(value = "/delete")
    public R delete(@ApiParam(value = "参数") @Valid @RequestBody IDEntity idEntity, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            companyDramasService.deletes(idEntity.getId());
        }
        return result;
    }


    @ApiOperation(value = "恢复剧目")
    @PostMapping(value = "/recover")
    public R recover(@ApiParam(value = "参数") @Valid @RequestBody IDEntity idEntity, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            companyDramasService.recover(idEntity.getId());
        }
        return result;
    }


}